# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Dmytro Meleshko <qzlgeb.zryrfuxb@tznvy.pbz(rot13)>

pkgname=eslint-language-server
pkgver=2.4.2
pkgrel=1
pkgdesc='Language server for ESLint'
arch=('any')
url=https://github.com/Microsoft/vscode-eslint
license=('MIT')
depends=('nodejs')
makedepends=('git' 'npm')
conflicts=("vscode-$pkgname")
replaces=("vscode-$pkgname")
source=("git+$url.git#tag=release/$pkgver")
b2sums=('SKIP')

prepare() {
  cd vscode-eslint
  npm ci
}

build() {
  cd vscode-eslint
  npm run compile:server
}

package() {
  install -d "$pkgdir"/usr/{bin,lib/node_modules/$pkgname}
  printf '%s\n' '#!/usr/bin/env node' "require('/usr/lib/node_modules/$pkgname/out/eslintServer.js');" >"$pkgdir"/usr/bin/$pkgname
  chmod +x "$pkgdir"/usr/bin/$pkgname
  ln -s $pkgname "$pkgdir"/usr/bin/vscode-$pkgname

  cd vscode-eslint
  install -Dm644 -t "$pkgdir"/usr/share/doc/$pkgname README.md
  install -Dm644 -t "$pkgdir"/usr/share/licenses/$pkgname License.txt

  cd server
  cp -r node_modules out package.json "$pkgdir"/usr/lib/node_modules/$pkgname
}
